package net.lb.io.json.serializer;

import java.lang.reflect.Type;
import net.lb.baseutil.collection.ObjectCollect;
import net.lb.baseutil.collection.StringCache;
import net.lb.io.json.field.JsonField;
import net.lb.io.json.util.JsonSerializer;

public class LongSerializer implements JsonSerializer
{
    @Override
    public Object transToJsonvalue(Object src, ObjectCollect collect)
    {
        return src;
    }
    
    @Override
    public void setJsonFields(JsonField[] jsonFields)
    {
        
    }
    
    @Override
    public void writeToString(StringCache cache, Object value, ObjectCollect collect)
    {
        cache.append(((Long) value).longValue());
    }
    
    @Override
    public Object toBean(Object value, Type type)
    {
        if (type.equals(Long.class))
        {
            return ((Number) value).longValue();
        }
        else if (type.equals(Integer.class))
        {
            return ((Number) value).intValue();
        }
        else if (type.equals(Short.class))
        {
            return ((Number) value).shortValue();
        }
        else
        {
            return ((Number) value).byteValue();
        }
    }
}
